package utils

import (
	"go-weiqi-system/internal/models"
	"net/http"

	"github.com/gin-gonic/gin"
)

// Success 成功响应
func Success(c *gin.Context, data interface{}, message ...string) {
	msg := "success"
	if len(message) > 0 {
		msg = message[0]
	}
	c.JSON(http.StatusOK, models.Success(data, msg))
}

// Error 错误响应
func Error(c *gin.Context, message string, code ...int) {
	statusCode := http.StatusBadRequest
	errCode := 400
	if len(code) > 0 {
		errCode = code[0]
		if errCode >= 500 {
			statusCode = http.StatusInternalServerError
		}
	}
	c.JSON(statusCode, models.Error(message, errCode))
}

// Unauthorized 未授权响应
func Unauthorized(c *gin.Context, message string) {
	c.JSON(http.StatusUnauthorized, models.Error(message, 401))
}

// NotFound 未找到响应
func NotFound(c *gin.Context, message string) {
	c.JSON(http.StatusNotFound, models.Error(message, 404))
}
